import axios from "axios";
let isDev = process.env.NODE_ENV === "development";
let baseURL;
if (isDev) {
  baseURL = "/api";
} else {
  baseURL = "";
}
const service = axios.create({
    baseURL,
    timeout: 1000000000
})

service.interceptors.request.use((config) => {
    return config
}, (err) => {
    return Promise.reject(err)
})

service.interceptors.response.use((response) => {
    return response
}, (err) => {
    return Promise.reject(err)
})

export function post(url, params) {
    return new Promise((reslove, reject) => {
        service.post(url, params, {
            headers: {
                "Content-Type": 'application/json'
            }
        }).then((res) => {
            reslove(res)
        }).catch((e) => {
            reject(e);
        })
    })
}
export function get(url, params) { 
    return new Promise((reslove, reject) => {
        service.get(url, {params}, {
            headers: {
                "Content-Type": 'application/json'
            }
        }).then((res) => {
            reslove(res)
        }).catch((e) => {
            reject(e);
        })
    })
}